﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace Sai_Se_Dung
{
    /// <summary>
    /// Using Xna Audio Library
    /// </summary>
    public static class Sound
    {
        /// <summary>
        /// Play Sound
        /// </summary>
        /// <param name="path"></param>
        public static void PlaySound(string path)
        {
            try
            {
                if (!string.IsNullOrEmpty(path))
                {
                    using (var stream = TitleContainer.OpenStream(path))
                    {
                        if (stream != null)
                        {
                            var effect = SoundEffect.FromStream(stream);
                            FrameworkDispatcher.Update();
                            effect.Play();
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// Stop Sound
        /// </summary>
        /// <param name="path"></param>
        public static void StopSound(string path)
        {

            try
            {
                if (!string.IsNullOrEmpty(path))
                {
                    using (var stream = TitleContainer.OpenStream(path))
                    {
                        if (stream != null)
                        {
                            var effect = SoundEffect.FromStream(stream);
                            FrameworkDispatcher.Update();
                            effect.Dispose();
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
